package com.newmuis.open.codeeval.easy;

/**
 * CodeEval.com > Easy Challenges > Sum of Primes
 * 
 * Description:
 * 
 * Write a program to determine the sum of the first 1000 prime numbers.
 * 
 * Input sample:
 * 
 * None
 * 
 * Output sample:
 * 
 * Your program should print the sum on stdout.i.e.
 * 
 * 3682913
 * 
 * 
 * @author Jonathan Newmuis (jon@newmuis.com)
 * @category easy
 * 
 */
public class sum_prime {
	/**
	 * Determines whether an integer is prime.
	 * 
	 * @param integer the integer to determine whether it is prime.
	 * @return true if and only if the specified integer {@code x} is prime.
	 */
	private static boolean isPrime(final int x) {
		boolean prime = true;
		for (int i = 2; i < x; i++) {
			if (x % i == 0) {
				prime = false;
			}
		}
		return prime;
	}

	/**
	 * @param args No arguments should be specified. Any specified arguments are ignored.
	 */
	public static void main(final String[] args) {
		int sum = 0;

		// Calculate the sum of the first 1000 prime integers
		for (int i = 2, primeCount = 0; primeCount < 1000; i++) {
			if (isPrime(i)) {
				sum += i;
				primeCount++;
			}
		}

		// Output the sum.
		System.out.println(sum);
	}
}
